package com.jackchong.base

import androidx.appcompat.app.AppCompatActivity
import com.jackchong.utils.ToastUtils
import com.kongzue.dialog.util.DialogSettings
import com.kongzue.dialog.v3.MessageDialog
import com.kongzue.dialog.v3.TipDialog
import com.kongzue.dialog.v3.WaitDialog

/**
 * author : chong.huang
 * create : 8/7/21
 * desc   :
 */
object JWindow {

    fun toastE(msg: Any?) {
        ToastUtils.e(msg)
    }

    fun toastW(msg: Any?) {
        ToastUtils.w(msg)
    }

    fun toastS(msg: Any?) {
        ToastUtils.success(msg)
    }

    fun showLoading(activity: AppCompatActivity) {
        WaitDialog.show(activity, "")
    }

    fun hideLoading() {
        WaitDialog.dismiss()
    }

    fun showTip(type: JToast.Type, message: String?) {
        JToast.show(type, message)
    }


    fun AppCompatActivity.dialog(message: String, click: () -> Any, title: String = "提示", okButton: String = "确定", noButton: String = "取消") {
        MessageDialog.show(this, title, message, okButton, noButton).setOnOkButtonClickListener { baseDialog, v ->
            val results = click()
            if (results is Boolean){
                results
            }else
                false
        }
    }
}